package group_3李禹江;

import java.io.*;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by Administrator on 2017/12/21.
 */
public class Test01 {
    public static void main(String[] args) {
         //存储数据
        Map<String, Integer> map = new HashMap<>();
        Map<String, Integer> map1 = new HashMap<>();
         //        map.put("160101100",0);
        //字符流读文件
        BufferedReader reader = null;
        try {
            reader = new BufferedReader(new FileReader("D:\\data\\key.txt"));

            String stuNo = null;

            while ((stuNo = reader.readLine()) != null) {
                stuNo=stuNo.trim();    //读数据时自动去除空格
                map.put(stuNo, 0);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                reader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

                //得到一个文件夹的所有文件
        File file = new File("D:\\data\\16信本2班Java作业一");

        File[] files = file.listFiles();
            String name=null;
        for (File f : files) {
            String fileName = f.getName();
            String no = null;
            String Fno=null;
            Matcher matcher = Pattern.compile("信本2班(\\d+)(.*)作业").matcher(fileName);
                //信本2班1606101025黄宇作业

            while (matcher.find()) {
                no = matcher.group(1);
                name = matcher.group(2);
                //如果学号不是10位数   则输入错误
                //我在作业文件中将黄宇的作业学号删除了2位数
                if (no.length()!=10){
                    Fno=no;
                    System.out.println("警告！");
                    System.out.println(fileName+"     "+"该作业学号错误！");
                }
                //System.out.println(no);
            }
            map.put(no, 1);
            map1.put(name,1);

        }
                 //打印所有value为0
                System.out.println("没交作业的人的学号：");
        for (Map.Entry<String, Integer> entry : map.entrySet()) {

            if (entry.getValue() == 0) {

                System.out.println(entry.getKey());
            }
        }
        //已交作业人的名单
        System.out.println("已交作业的人的名单：");
        for (Map.Entry<String, Integer> entry : map1.entrySet()) {

            if (entry.getValue() == 1) {

                System.out.println(entry.getKey());
            }
        }

    }
}
